let arrawStep = [
  [{ x: -1, y: 0 }, { x: 1, y: 0 }],
  [{ x: 0, y: -1 }, { x: 0, y: 1 }],
  [{ x: -1, y: -1 }, { x: 1, y: 1 }],
  [{ x: -1, y: 1 }, { x: 1, y: -1 }],
]


function checkSameTypeCount(chessArray, xAres, yAres, chessType, xStep, yStep) {
  let count = 0
  for (let i = 1; i < 5; i++) {
      let tempX = xAres + i * xStep;
      let tempY = yAres + i * yStep;
      if (tempX < 0 || tempX > 14 || tempY < 0 || tempY > 14) {
          break;
      }
      if (chessArray[tempX][tempY] === chessType) {
          count++
      } else {
          break;
      }
  }
  return count
}


let checkGobangChessWin = function(chessArray, xAres, yAres, chessType) {
  for (let i = 0; i < arrawStep.length; i++) {
      let arrow = arrawStep[i]
      let step1 = arrow[0]
      let step2 = arrow[1]
      let temp1Count = checkSameTypeCount(chessArray, xAres, yAres, chessType, step1.x, step1.y)
      let temp2Count = checkSameTypeCount(chessArray, xAres, yAres, chessType, step2.x, step2.y)
      if (temp1Count + temp2Count >= 4) {
          return true;
      }
  }
  return false
}

export default checkGobangChessWin;